package br.sc.senai.view;

import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JMenuBar;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Component;
import java.util.Date;

import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.ButtonGroup;
import java.awt.Font;

import br.sc.senai.util.Data;


@SuppressWarnings("serial")
public class PrincipalUI extends JFrame {
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private static PrincipalUI instancia;
	
	public static PrincipalUI obterInstancia(){
		if ( instancia == null ){
			instancia = new PrincipalUI();
		}
		return instancia;
	}
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					PrincipalUI frame = obterInstancia();
					frame.setExtendedState(frame.getExtendedState()
							| JFrame.MAXIMIZED_BOTH);
					//frame.setContentPane(new JLabel(new ImageIcon(PrincipalUI.class.getResource("/br/sc/senai/icones/cool.jpg"))));
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	/**
	 * Create the frame.
	 */
	public PrincipalUI() {
		setTitle("Lopa Filtros");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1024, 768);
		this.setMinimumSize(new Dimension(1024, 768));

		JMenuBar menuBar = new JMenuBar();	

		setJMenuBar(menuBar);

		Component horizontalStrut_1 = Box.createHorizontalStrut(15);
		menuBar.add(horizontalStrut_1);

		JLabel lblLopaFiltros = new JLabel("Lopa Filtros");
		lblLopaFiltros.setFont(new Font("Dialog", Font.BOLD, 20));
		menuBar.add(lblLopaFiltros);

		Component glue = Box.createGlue();
		menuBar.add(glue);

		JLabel label = new JLabel(Data.formatarDataPrincipal(new Date(System
				.currentTimeMillis())));
		label.setFont(new Font("Dialog", Font.BOLD, 16));
		menuBar.add(label);

		Component horizontalStrut = Box.createHorizontalStrut(15);
		menuBar.add(horizontalStrut);

		JButton btnVendas = new JButton("Vendas");
		btnVendas.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ConsultarVendasUI consultarVendasUI = ConsultarVendasUI.obterInstancia();
				consultarVendasUI.setFocusable(true);
				consultarVendasUI.moveToFront();
				consultarVendasUI.requestFocus();
				getContentPane().add(consultarVendasUI);
				consultarVendasUI.setVisible(true);
			}
		});
		btnVendas.setIcon(new ImageIcon(PrincipalUI.class.getResource("/br/sc/senai/icones/Shopping_basket_Icon_48.png")));
		btnVendas.setFont(new Font("Dialog", Font.BOLD, 18));
		buttonGroup.add(btnVendas);

		JButton btnServios = new JButton("Clientes");
		btnServios.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ConsultarClientesUI consultarClientesUI = ConsultarClientesUI.obterInstancia();
				consultarClientesUI.setFocusable(true);
				consultarClientesUI.moveToFront();
				consultarClientesUI.requestFocus();
				getContentPane().add(consultarClientesUI);
				consultarClientesUI.setVisible(true);
			}
		});
		btnServios.setIcon(new ImageIcon(PrincipalUI.class.getResource("/br/sc/senai/icones/user_clients_01.png")));
		btnServios.setFont(new Font("Dialog", Font.BOLD, 18));
		buttonGroup.add(btnServios);

		JButton btnRelatrios = new JButton("Relatório de Vendas");
		btnRelatrios.setFont(new Font("Dialog", Font.BOLD, 18));
		buttonGroup.add(btnRelatrios);
		btnRelatrios.setIcon(new ImageIcon(PrincipalUI.class.getResource("/br/sc/senai/icones/Adobe_PDF_Document_Icon_48.png")));

		JButton btnHistricoDeEntrada = new JButton("Histórico de Estoque");
		btnHistricoDeEntrada.setIcon(new ImageIcon(PrincipalUI.class.getResource("/br/sc/senai/icones/preferences_system_time.png")));
		btnHistricoDeEntrada.setFont(new Font("Dialog", Font.BOLD, 18));
		buttonGroup.add(btnHistricoDeEntrada);

		JButton btnAdicionarEstoque = new JButton("Adicionar Estoque");
		btnAdicionarEstoque.setIcon(new ImageIcon(PrincipalUI.class.getResource("/br/sc/senai/icones/Add_48x48.png")));
		btnAdicionarEstoque.setFont(new Font("Dialog", Font.BOLD, 18));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addComponent(btnVendas, GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
					.addComponent(btnServios, GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
					.addComponent(btnRelatrios, GroupLayout.PREFERRED_SIZE, 206, Short.MAX_VALUE)
					.addComponent(btnAdicionarEstoque, GroupLayout.PREFERRED_SIZE, 204, Short.MAX_VALUE)
					.addComponent(btnHistricoDeEntrada, GroupLayout.PREFERRED_SIZE, 206, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(btnVendas, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
				.addComponent(btnServios, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
				.addComponent(btnRelatrios, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
				.addComponent(btnAdicionarEstoque, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
				.addComponent(btnHistricoDeEntrada, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
		);
		getContentPane().setLayout(groupLayout);
	}
}
